<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');



$focus = new edanz_Feedback();
if(isset($_REQUEST['record'])) {
    $focus->retrieve($_REQUEST['record']);
}
if(isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') {
    $focus->id = "";
}

if(isset($_REQUEST['related_editor_id'])) {
	$focus->related_editor_id = $_REQUEST['related_editor_id'];
}

if(isset($_REQUEST['related_editor_name'])) {
        $focus->related_editor_name = $_REQUEST['related_editor_name'];
}

if(isset($_REQUEST['name'])) {
        $focus->name = $_REQUEST['name'];
}

$json = getJSONobj();

$ss = new Sugar_Smarty();
$ss->assign("MOD", $mod_strings);
$ss->assign("APP", $app_strings);

$title_params = '';

if(isset($focus->id)) {
	$title_params .= '<a href="index.php?module=edanz_Feedback&amp;action=DetailView&amp;record='.$focus->id.'">'.$focus->name.'</a><span class="pointer">&raquo;</span>';
}
$title_params .= $mod_strings['LBL_CONSTRUCT'];

$ss->assign("TITLE_PARAMS", $title_params);
if (isset($_REQUEST['return_module'])) $ss->assign("RETURN_MODULE", $_REQUEST['return_module']);
if (isset($_REQUEST['return_action'])) $ss->assign("RETURN_ACTION", $_REQUEST['return_action']);
if (isset($_REQUEST['return_id'])) $ss->assign("RETURN_ID", $_REQUEST['return_id']);
// handle Create $module then Cancel
if (empty($_REQUEST['return_id'])) {
    $ss->assign("RETURN_ACTION", 'index');
}
if (isset($_REQUEST['deliverable_id'])) $focus->deliverable_id = $_REQUEST['deliverable_id']; 

$focus->load_relationship('feedbackpoints');

$feedback_points = $focus->feedbackpoints->get();

    $point_count = 0;
    $point_html = ' ';
    if(count($feedback_points)>0){

        foreach($feedback_points as $fp_id){
        //retrieve feedback point
             $fp = new edanz_FeedbackPoint();
             $fp_focus = $fp->retrieve($fp_id);
             $point_html .= "<div id='existing_point".$point_count."'> <table class='tabDetailViewDL2' width='100%'><tr class='tabDetailViewDL2' >" ;
             $point_html .= "<td width='25%'> <input id='existing_point_name". $point_count ."' type='hidden' type='text' size='60' maxlength='255' name='existing_point_name". $point_count ."'  value='". $fp_focus->name."' >". $fp_focus->name."</td>";
             $point_html .= "<td width='25%'><input type='hidden' size='60' maxlength='255' name='existing_point_category". $point_count ."'   id='existing_point_category". $point_count ."' value='".$app_list_strings['feedback_point_category_list'][$fp_focus->category]."' >".$app_list_strings['feedback_point_category_list'][$fp_focus->category];
             $point_html .= "<input type='hidden' name='added_point_id". $point_count ."' id='added_point_id". $point_count ."' value='". $fp_focus->id ."' ></td>";
             $point_html .= "<input id='existing_point_description". $point_count ."' type='hidden' type='text' name='existing_point_description". $point_count ."'  value='". $fp_focus->description."' >";
             $point_html .= "<td><a href='#' onclick=\"javascript:remove_existing_point('existing_point".$point_count."','".$fp_focus->id."'); \" >  ";
             $point_html .= "<img src='".SugarThemeRegistry::current()->getImageURL("delete_inline.gif")."' border='0' alt='rem' align='absmiddle' border='0' height='12' width='12'>". $mod_strings['LBL_REMOVE']."</a></td></tr></table></div>";


          $point_count =$point_count +1;
        }

        $point_html  .= "<div id='no_points'></div>";
    }else{
        $point_html  .= "<div id='no_points'><table width='100%' border='0' cellspacing='0' cellpadding='0'><tr class='evenListRowS1'><td>".$mod_strings['LBL_NONE']."</td></tr></table></div>";

    }
    $ss->assign('EXISTING_POINTS', $point_html );
$ss->assign("POINT_COUNT", $point_count );




$popup_request_data = array(
    'call_back_function' => 'set_return',
    'form_name' => 'feedbackform',
    'field_to_name_array' => array(
        'id' => 'related_editor_id',
        'name' => 'related_editor_name',
        ),
    );
$ss->assign('encoded_users_popup_request_data', $json->encode($popup_request_data));

    $popup_request_data = array(
        'call_back_function' => 'set_return_feedback_point',
        'form_name' => 'feedbackform',
        'field_to_name_array' => array(
            'id' => 'popup_feedback_point_id',
            'name' => 'popup_feedback_point_name',
            'category' => 'popup_feedback_point_category',
            'description' => 'popup_feedback_point_description',

            ),
        );

$ss->assign('encoded_feedback_point_popup_request_data', $json->encode($popup_request_data));

$ss->assign('REMOVE_IMAGE_PATH', SugarThemeRegistry::current()->getImageURL("delete_inline.gif"));

$ss->assign("ID", $focus->id);
$ss->assign("DELIVERABLE_ID", $focus->deliverable_id);
$ss->assign("FEEDBACK_NUMBER", $focus->feedback_number);
if($focus->id)
{
	$ss->assign("R2JOBNUMBER_C", $focus->r2jobnumber_c);
	$ss->assign("R2JOBNAME_C", $focus->r2jobname_c);
	$ss->assign("R2JOBURL_C", $focus->r2joburl_c);
	$ss->assign("CC_C", $focus->cc_c);
}
else
{
	$ss->assign("R2JOBNUMBER_C", $_REQUEST['r2jobnumber']);
	$ss->assign("R2JOBNAME_C", $_REQUEST['r2jobname']);
	$ss->assign("R2JOBURL_C", urldecode($_REQUEST['r2joburl']));
	$ss->assign("CC_C", "senioreditors@edanzgroup.com, qc@edanzgroup.com");
}
require_once 'modules/ACLRoles/ACLRole.php';
$objACLRole = new ACLRole();
$roles = $objACLRole->getUserRoles($GLOBALS['current_user']->id);

$ss->assign('NAME_OPTIONS', get_select_options_with_id($app_list_strings['feedback_name_dom'], $focus->name));
$quality_ratings = array();
$checked_string = '';
foreach($app_list_strings['quality_ratings'] as $key=>$val){
	if(isset($focus->id) && $key == $focus->quality_rating)
		$checked_string = ' checked';
	$quality_ratings[] = array('numeric_rating'=>$key, 'description'=>$val, 'checked_string'=>$checked_string);
	$checked_string = '';
}
$ss->assign('QUALITY_RATINGS', $quality_ratings);
$ss->assign("RELATED_EDITOR_NAME", $focus->related_editor_name);
$ss->assign("RELATED_EDITOR_ID", $focus->related_editor_id );
$ss->assign("ATTACHMENT", $focus->attachment_c);
$ss->assign("ATTACHMENT_NAME", $focus->attachment_name_c);
$ss->assign("DESCRIPTION", $focus->description );
$ss->assign("FEEDBACK_POINT_CATEGORIES", implode(',', $app_list_strings['feedback_point_category_list']));

$ss->display("modules/edanz_Feedback/tpls/FeedbackConstruction.tpl");

?>

